<template>
    <div class="changeBox">
        <div class="closeBox">
            <div @click="$emit('close')"></div>
        </div>
        <div class="UserBox1">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                        <td width="23%">会员帐号：{{sUserId}}</td>
                    <td width="20%">昵称设置：{{sNickname}}</td>
                    <td width="27%">注册日期：{{sAddDate}}</td>
                    <td width="30%" style="text-align:right">上次登录时间：{{sLastLoginTime}}</td>
                </tr>
            </table>
        </div>
        <form class="UserBox2">
            <div class="Number2">
                <p>修改密码： <input  type="password" v-model="OldPwd"  placeholder="输入原密码"></p>
                <p> <input  type="password" v-model="NewPwd" :class="{'No':offBalance}" placeholder="输入新密码"></p>
                <p> <input  type="password" v-model="NewPwd2" :class="{'No':offBalance}" placeholder="确认新密码"></p>
                <p style="color:red">{{offBalance}}</p>
            </div>
            <div class="Number3">
                <p>
                    <input type="button" value="" @click="changePassword">
                </p>
            </div>
        </form>
    </div>
</template>
<script>
export default {
    name:"changeInit",
    data(){
		return {
			OldPwd:"",
			NewPwd:"",
			NewPwd2:""
		}
	},
	computed:{
		// 仓库信息
		sUserId(){
			return this.$store.getters["User/UserId"]
		},
		sNickname(){
			return this.$store.getters["User/Nickname"]
		},
		sAddDate(){
			return this.$store.getters["User/AddDate"]
		},
		sLastLoginTime(){
			return this.$store.getters["User/LastLoginTime"]
		},
		offBalance(){
			if(this.NewPwd!=this.NewPwd2&&this.NewPwd2!=''){
				return "两次密码不一样";
			}
			return '';
		}
	},
	methods:{
		changePassword(){
			var OldPwd=this.OldPwd;
			var NewPwd=this.NewPwd;
			var offBalance=this.offBalance;
			if(!OldPwd||!NewPwd){
				this.$store.commit("changeTips",{data:"请输入密码"});
				return false;
			}
			if(offBalance){
				return false;
			}
			var data={
				UserId,
				RandCode,
				OldPwd,
				NewPwd,
			}
			$.ajax({
				url:Api.user,
				type:"POST",
				data,
				success:(data)=>{
					this.$store.commit("changeTips",{data:"修改密码成功"})
					this.OldPwd="";
					this.NewPwd="";
					this.NewPwd2="";
					this.$emit('close');
				},
				error:(data)=>{
					this.$store.commit("changeTips",{data})
				}
			})
			// 因为要SIGNAIR没办法- -
			// axios.post("http://192.168.1.164:49769/api/User",data)
			// .then(el => {
			// 	if(el.data.State==1000){
			// 		alert("修改密码成功");
			// 		this.OldPwd="";
			// 		this.NewPwd="";
			// 		this.NewPwd2="";
			// 		this.$emit('close');
			// 	}else{
			// 		alert(el.data.Msg)
			// 	}
			// })
			// .catch(el => {
			// })
		}
	}
}
</script>
